package com.situ.studentmanagement;

import com.situ.studentmanagement.model.CheckInfo;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by niugao on 7/18/2016.
 */
public class Utils {
    //取一个一个日期所在月的第0天的字符串形式的表示
    public static String getFirstDayOfMonthString(Date date) {
        if (date == null)
            return "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-00");
        return sdf.format(date);
    }

    //获取一个日期所在月份的最后一天，也就是其下一个月的第0天
    public static String getLastDayOfMonthString(Date date) {
        if (date == null)
            return "";
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, 1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-00");
        return sdf.format(calendar.getTime());
    }

    //获取时间中日期部分的字符串
    public static String getDateStringForDay(Date date) {
        if (date == null)
            return "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    //获取时间中时间部分的字符串
    public static String getDateStringForTime(Date date) {
        if (date == null)
            return "";
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return sdf.format(date);
    }

    //获取一天开始的时间点
    public static Date getDayBeginTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 001);
        return new Date(cal.getTimeInMillis());
    }

    public static void setStatusToLated(List<CheckInfo> latedChecks) {
        for (CheckInfo ci : latedChecks) {
            ci.setStatus("迟到了");
        }
    }

    public static void setStatusToLabsenced(List<CheckInfo> latedChecks) {
        for (CheckInfo ci : latedChecks) {
            ci.setStatus("旷课了");
        }
    }
}
